<%@page import="BUS.BUSProduct"%>
<%@page import="BUSObject.Product"%>
<%@page import="java.util.ArrayList"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%-- 
    Document   : index
    Created on : Jul 16, 2011, 10:15:58 PM
    Author     : HOANG ANH
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib tagdir="/WEB-INF/tags/template/" prefix="template" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to Soft Drink World</title>
    </head>

    <%
        BUSProduct _busPro = new BUSProduct();

        ArrayList<Product> proList = _busPro.getProductList();
        boolean isNull = (proList == null);
    %>
    <template:header level="0"></template:header>
    <template:StartContent level="0"></template:StartContent>
    <h1>Welcome to Soft Drink World</h1>
    
    <c:choose>
        <c:when test="<%=isNull%>">
            <h1>Error Connect</h1>
        </c:when>
        <c:when test="<%=proList.isEmpty()%>">
            <h1>No Drink</h1>
        </c:when>
        <c:otherwise>
            <table border="1" cellpadding="2">
                <thead>
                    <tr>
                        <th>Drink ID</th>
                        <th>Name</th>
                        <th>Price</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        for (int i = 0; i < proList.size(); i++) {
                    %>

                <form action="AddToCart.jsp" method="POST">
                    <tr>
                        <td><%= proList.get(i).getID()%></td>
                        <td><%= proList.get(i).getName()%></td>
                        <td><%= proList.get(i).getPrice()%></td>
                        <td><input type="submit" value="Add2Cart" /></td>
                    <input type="hidden" name="ID" value="<%= proList.get(i).getID()%>" />
                    <input type="hidden" name="Name" value="<%= proList.get(i).getName()%>" />
                    <input type="hidden" name="Price" value="<%= proList.get(i).getPrice()%>" />
                    </tr>                
                </form>
                <%}%>
            </tbody>
        </table>
    </c:otherwise>
</c:choose>
<br/>
<a href="ViewCart.jsp">View Your Cart</a>
<template:EndContent></template:EndContent>
<template:Footer></template:Footer>
</html>
